<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<script type="text/javascript">

$(function(){
	//初始化表单验证
	$("#template").validate({
		rules: {
			gbprice: {isMoney: true},
		},
		messages: {
			name: {required: "请输入商品标题"},
		},
		submitHandler:function(form){
			$(form).ajaxSubmit({
				success:function(data){
					switch(data.flag){
					case 2:
						Kit.alert("该模板已添加,请重新编辑模板名称");return;
					/* case -1:
						Kit.alert("网络繁忙...，请重试");return;  */
					case  -1:
						/* dataPaginator.loadPage(1); */
						TemDialog.close();
						return;
					}
				}
			});
		}
	});
}); 
/* 点击新增扩展信息 */ 
$(document).ready(function(){
    $("#addTemplate").click(function(){
    	var tr="<tr><td><input class=\"form-control\" name=\"iname\" placeholder=\"属性名称\">"+
    		"<td><input class=\"form-control\" name=\"idetail\" placeholder=\"属性值\">"+
			"</td><td><input type=\"checkbox\" name=\"check\" checked=\"checked\" />"+
			"</td></tr>";
			$("#table").append(tr);
    });
    $("#deleteTemplate").click(function(){
        var check = document.getElementsByName("check");
        for(var i=0;i<check.length;i++){
            if(check[i].checked){
                 document.getElementById('table').deleteRow(i);
                 i--;
            }
        }
    });
})
$(function () {
	//全选或全不选
	$("#all").click(function(){   
    	if(this.checked){   
        	$("#table :checkbox").prop("checked", true);  
    	}else{   
		    $("#table :checkbox").prop("checked", false);
    	}   
 	}); 
});

</script>
<form id="template" action="${BASE_PATH}/bus/goods/base/template" method="post" class="form-horizontal" style="">
<div class="form-group">
 		<label class="col-lg-2 control-label"><span style="margin-right:10px; color:red;">*</span>关联模板</label>
			<div class="col-lg-9">
				<select id="templateid" name="templateid" class="selectpicker pull-left p-l-5" data-width="260px">
					<option>请选择</option>
					<c:forEach items="${allGoodsTemplates}" var="goodsTemplate">
						<option value="${goodsTemplate.id}" <c:if test="${goodsTemplate.id==saleGT.templateid}">selected</c:if>>${goodsTemplate.name}</option>
					</c:forEach>
				</select>				 	
			<input type="text" id="goodsid" name="goodsid" hidden="hidden" value="${goodsid}"/>
			</div>
		<div class="clearfix"></div>
	</div>
	<div class="btn-group">
 		<label class="search-label">扩展属性操作：</label>
		<button type="button" class="btn btn-default" title="新建" id="addTemplate">
			<i class="fa fa-file-o"></i> 扩展属性新增
		</button>
		<button type="button" class="btn btn-default" title="删除" id="deleteTemplate">
			<i class="fa fa-file-o"></i> 扩展属性删除
		</button>
	</div>
	<div>
		<table class="table table-bordered table-striped">
			<tr>
				<td>扩展属性</td>
				<td>
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<td>属性名称</td>
								<td>属性值</td>
								<td>全选<input type="checkbox" name="all" id="all" οnclick=all><br></td>
							</tr>
						</thead>
						<tbody id="table">
							<c:if test="${allItems != null}">
								<c:forEach items="${allItems}" var="item" varStatus="s">
									<tr>
										<td><input class="form-control" name="iname" placeholder="属性名称" value="${item.iname}"></td>
										<td><input class="form-control" name="idetail" placeholder="属性值" value="${item.idetail}"></td>
										<td>
											<input type="checkbox" name="check" checked="" />
										</td>								
									</tr>
								</c:forEach>
							</c:if>
						</tbody> 
					</table>
				</td>
			</tr>
		</table>
	</div>
	<div class="row">
		<div class="col-lg-6"><button class="btn btn-primary col-sm-3 pull-right" type="submit" autocomplete="off" >提交</button></div>
		<div class="col-lg-6"><button class="btn btn-default col-sm-3 pull-left"  type="button" onclick="javascript:TemDialog.close();" autocomplete="off">取消</button></div>
	</div>
</form>